package cn.lg.soar.activiti.client;

import cn.lg.soar.activiti.api.constant.ModuleConst;
import cn.lg.soar.activiti.api.model.*;
import cn.lg.soar.activiti.api.service.IActivitiApi;
import cn.lg.soar.activiti.service.ActivitiService;
import cn.lg.soar.core.annotations.ApiClient;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ApiIgnore
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/activiti")
public class ActivitiApiClient implements IActivitiApi {

	@Autowired
	private ActivitiService service;

	@Override
	@PostMapping("startProcess")
	@Operation(summary = "启动流程", description = "启动流程")
	public ProcessInstanceDTO startProcess(@RequestBody @Valid StartProcessDTO dto) {
		return service.startProcess(dto);
	}

	@Override
	@PostMapping("completeTask")
	@Operation(summary = "完成任务", description = "完成任务")
	public void completeTask(@RequestBody @Valid CompleteTaskDTO dto) {
		service.completeTask(dto);
	}

	@Override
	@GetMapping("tasks")
	@Operation(summary = "批量查询任务", description = "批量查询任务")
	public List<TaskDTO> tasks(
			@RequestParam String processKey,
			@RequestParam Collection<String> businessIds,
			Collection<String> candidates
	) {
		return service.tasks(processKey, businessIds, candidates);
	}

	@Override
	@GetMapping("historyTasks")
	@Operation(summary = "查询历史任务", description = "查询历史任务")
	public List<HistoryTaskDTO> historyTasks(
			@RequestParam String processKey,
			@RequestParam String businessId
	) {
		return service.historyTasks(processKey, businessId);
	}

}
